﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Windows.Forms;

namespace Campaign_Manager
{
    public partial class Form1 : Form
    {
        private List<Settlement> Towns;
        private TreeNode treeTowns;
        private TreeNode treeNPCs;
        private TreeNode treePCs;
        private Databases Data;

        public Form1()
        {
            InitializeComponent();
            Data = new Databases();
            Towns = new List<Settlement>();
            treeCampaign.Nodes[0].Expand();
            treeTowns = treeCampaign.Nodes[0].Nodes[0];
            treeNPCs = treeCampaign.Nodes[0].Nodes[1];
            treePCs = treeCampaign.Nodes[0].Nodes[2];
        }

        private void createTownToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Settlement newSettle = new Settlement();
            frmSettlement frmSettle = new frmSettlement(newSettle);
            if (frmSettle.ShowDialog() == DialogResult.OK)
            {
                TreeNode newNode = new TreeNode(newSettle.getName());
                newNode.ContextMenuStrip = contextTown;
                newNode.Nodes.Add("Shops");
                newNode.Nodes[0].ContextMenuStrip = contextTownShop;
                newNode.Nodes.Add("NPCs");
                newNode.Nodes[1].ContextMenuStrip = contextTownNPC;
                Towns.Add(newSettle);
                int index = treeTowns.Nodes.Add(newNode);
                treeTowns.Nodes[index].ContextMenuStrip = contextTown;
                treeTowns.Expand();
            }
        }

        private void treeCampaign_DoubleClick(object sender, EventArgs e)
        {
            if (treeCampaign.SelectedNode.Parent == treeCampaign.Nodes[0].FirstNode)
            {

            }
        }

        private void newCampaignToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddCampaign newCampaign = new frmAddCampaign();
            newCampaign.ShowDialog();
            if (newCampaign.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                if (newCampaign.Pass())
                    Data.WriteCampaign(newCampaign.campName(), newCampaign.campCreator(), newCampaign.Pass(), newCampaign.campPassword());
                else
                    Data.WriteCampaign(newCampaign.campName(), newCampaign.campCreator(), newCampaign.Pass(), "");
                System.Windows.Forms.MessageBox.Show("Name: " + newCampaign.campName() + "\nCreator: " + newCampaign.campCreator() + "\nPassword: " + newCampaign.Pass().ToString() + " " + newCampaign.campPassword() + "\nDate: " + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Year.ToString());
            }
            newCampaign.Dispose();
            treeCampaign.Visible = true;
        }

        private void createMonsterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmMonster monster = new frmMonster();
            monster.ShowDialog();
        }
    }
}
